package com.feihong.yw189.paidan.qiangdanservice.newversion;


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.feihong.yw189.bluetooth.utils.util.ConstantsValue;
import com.feihong.yw189.bluetooth.utils.util.PrefUtils;


/**
 * Created by Sabirjan
 */
public class RemoteBroadcastRecieve extends BroadcastReceiver {

    boolean isFirst = true;

    @Override
    public void onReceive(final Context context, Intent intent) {


        if (isFirst) {
            isFirst = false;
            while (PrefUtils.getBoolean(context, ConstantsValue.PAIDAN_STATE, false)) {
                try {
                    Thread.sleep(2000);
                    if (!PrefUtils.getBoolean(context, ConstantsValue.PAIDAN_STATE, false)) {
                        context.stopService(new Intent(context, DaemonService.class));
                        return;
                    }
                    Log.i("派单", "onReceive: RemoteBroadcastRecieve");
                    context.startService(new Intent(context, DaemonService.class));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}